/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import java.util.HashMap;
import java.util.Map;

/**
 * Class to implement the Ember Enumeration <b>EmberKeyStructBitmask</b>.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public enum EmberKeyStructBitmask {
    /**
     * Default unknown value
     */
    UNKNOWN(-1),

    /**
     * The key has a sequence number associated with it.
     */
    EMBER_KEY_HAS_SEQUENCE_NUMBER(0x0001),

    /**
     * The key has an outgoing frame counter associated with it.
     */
    EMBER_KEY_HAS_OUTGOING_FRAME_COUNTER(0x0002),

    /**
     * The key has an incoming frame counter associated with it.
     */
    EMBER_KEY_HAS_INCOMING_FRAME_COUNTER(0x0004),

    /**
     * The key has a Partner IEEE address associated with it.
     */
    EMBER_KEY_HAS_PARTNER_EUI64(0x0008),

    /**
     * This indicates the key is authorized for use in APS data messages. If the key is not authorized
     * for use in APS data messages it has not yet gone through a key agreement protocol, such as CBKE
     * (i.e. ECC).
     */
    EMBER_KEY_IS_AUTHORIZED(0x0010),

    /**
     * This indicates that the partner associated with the link is a sleepy end device.  This bit is
     * set automatically if the local device hears a device announce from the partner indicating it
     * is not an 'RX on when idle' device.
     */
    EMBER_KEY_PARTNER_IS_SLEEPY(0x0020);

    /**
     * A mapping between the integer code and its corresponding type to
     * facilitate lookup by code.
     */
    private static Map<Integer, EmberKeyStructBitmask> codeMapping;

    private int key;

    static {
        codeMapping = new HashMap<Integer, EmberKeyStructBitmask>();
        for (EmberKeyStructBitmask s : values()) {
            codeMapping.put(s.key, s);
        }
    }

    private EmberKeyStructBitmask(int key) {
        this.key = key;
    }

    /**
     * Lookup function based on the EmberStatus type code. Returns null if the
     * code does not exist.
     *
     * @param code the code to lookup
     * @return enumeration value of the alarm type.
     */
    public static EmberKeyStructBitmask getEmberKeyStructBitmask(int code) {
        if (codeMapping.get(code) == null) {
            return UNKNOWN;
        }

        return codeMapping.get(code);
    }

    /**
     * Returns the EZSP protocol defined value for this enumeration.
     *
     * @return the EZSP protocol key
     */
    public int getKey() {
        return key;
    }
}
